#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 310;
const ll inf = 0x3f3f3f3f3f3f3f3f;

ll f[N][N][N][2], ans;
int n;
pii a[N];

inline void upd(ll &x, const ll &y) { x = x < y ? y : x; }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in; rep(i, 1, n) a[i].fi = in, a[i].se = in;
	a[++n] = { 0, 0 }; sort(a + 1, a + n + 1);
	memset(f, 0xcf, sizeof f);
	rep(i, 1, n) if(a[i].fi == 0 && a[i].se == 0) rep(k, 0, n) f[i][i][k][0] = 0;
	rep(len, 1, n) { 
		rep(l, 1, n - len + 1) {
			int r = l + len - 1;
			rep(k, 1, n) {
				upd(f[l][r][k][0], f[l][r][k][1] - 1ll * (a[r].fi - a[l].fi) * k);
				upd(f[l][r][k][1], f[l][r][k][0] - 1ll * (a[r].fi - a[l].fi) * k);
				ll c1 = 1ll * (a[l].fi - a[l - 1].fi) * k, c2 = 1ll * (a[r + 1].fi - a[r].fi) * k;
				if(r < n) upd(f[l][r + 1][k - 1][1], f[l][r][k][1] - c2 + a[r + 1].se);
				if(r < n) upd(f[l][r + 1][k][1], f[l][r][k][1] - c2);
				if(l > 1) upd(f[l - 1][r][k - 1][0], f[l][r][k][0] - c1 + a[l - 1].se);
				if(l > 1) upd(f[l - 1][r][k][0], f[l][r][k][0] - c1);
			}
		}
	}
	rep(i, 1, n) rep(j, 1, n) rep(k, 0, 1) upd(ans, f[i][j][0][k]); printf("%lld\n", ans);
}
